﻿using System.Xml;
using System.Collections.Generic;

namespace l1cs.server.model.npc.action
{

    public class L1NpcActionFactory
    {
        private static Logger _log = Logger.getLogger( typeof( L1NpcActionFactory ).FullName );

        private static Dictionary<string, L1NpcAction> _actions = new Dictionary<string, L1NpcAction>();

        //private static Constructor<L1NpcAction> loadConstructor(Class c)
        //        throws NoSuchMethodException {
        //    return c.getConstructor(new Class[] { Element.class });
        //}

        //static {
        //    try {
        //        _actions.put("Action", loadConstructor(L1NpcListedAction.class));
        //        _actions.put("MakeItem", loadConstructor(L1NpcMakeItemAction.class));
        //        _actions.put("ShowHtml", loadConstructor(L1NpcShowHtmlAction.class));
        //        _actions.put("SetQuest", loadConstructor(L1NpcSetQuestAction.class));
        //        _actions.put("Teleport", loadConstructor(L1NpcTeleportAction.class));
        //    } catch (NoSuchMethodException e) {
        //        _log.log(Level.SEVERE, "NpcActionのクラスロードに失敗", e);
        //    }
        //}

        public static L1NpcAction newAction( XmlReader reader )
        {
            L1NpcAction con = null;
            if ( string.Compare( reader.Name, "Action", true ) == 0 ) { con = new L1NpcListedAction( reader ); }
            else if ( string.Compare( reader.Name, "MakeItem", true ) == 0 ) { con = new L1NpcMakeItemAction( reader ); }
            else if ( string.Compare( reader.Name, "ShowHtml", true ) == 0 ) { con = new L1NpcShowHtmlAction( reader ); }
            else if ( string.Compare( reader.Name, "SetQuest", true ) == 0 ) { con = new L1NpcSetQuestAction( reader ); }
            else if ( string.Compare( reader.Name, "Teleport", true ) == 0 ) { con = new L1NpcTeleportAction( reader ); }
            else
            {
                _log.warning( reader.Name + " 未定義のNPCアクションです" );
            }
            return con;
            //try {
            //Constructor<L1NpcAction> con = _actions.get(element.getNodeName());
            //return con.newInstance(element);
            //} catch (NullPointerException e) {
            //    _log.warning(element.getNodeName() + " 未定義のNPCアクションです");
            //} catch (Exception e) {
            //    _log.log(Level.SEVERE, "NpcActionのクラスロードに失敗", e);
            //}
            //return null;
        }
    }
}
